package com.heima.article.controller.v1;

import com.heima.article.service.ArticleService;
import com.heima.common.constant.ArticleConstants;
import com.heima.model.article.dto.ArticleHomeDto;
import com.heima.model.common.dto.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
@Slf4j
public class ArticleHomeController {

    @Autowired
    private ArticleService articleService;

    // 首页加载
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        log.info("加载首页数据：{}",dto);
        return articleService.loadArticleList(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    // 加载更多  上拉加载
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        log.info("加载更多数据：{}",dto);
        return articleService.loadArticleList(dto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    // 加载最新  下拉刷新
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        log.info("加载最新数据：{}",dto);
        return articleService.loadArticleList(dto,ArticleConstants.LOADTYPE_LOAD_NEW);
    }
}
